"""
    栈
"""
from .linkedlist import LinkedList
from .exceptions import DataStructureIsEmpty


class MyStack:
    def __init__(self):
        self._stack = []

    def push(self, element):
        self._stack.append(element)

    def pop(self):
        if self.is_empty():
            raise StackIsEmpty("MyStack is empty")
        return self._stack.pop()

    def peek(self):
        if self.is_empty():
            raise StackIsEmpty("MyStack is empty")
        return self._stack[-1]

    def is_empty(self):
        return self._stack == []

    def get_size(self):
        return len(self._stack)


class StackIsEmpty(ValueError):
    pass


class LinkedListStack:
    def __init__(self):
        self._stack = LinkedList()

    def push(self, element):
        self._stack.add_first(element)

    def pop(self):
        if self._stack.is_empty():
            raise DataStructureIsEmpty("Push failed! LinkedListStack is empty")
        return self._stack.remove_first()

    def peek(self):
        if self._stack.is_empty():
            raise DataStructureIsEmpty("Push failed! LinkedListStack is empty")
        return self._stack.get_first()

    def is_empty(self):
        return self._stack.is_empty()

    def get_size(self):
        return self._stack.get_size()